<template>
  <div class="fixed">
    <div class="top">
      <span @click="close">
        <svg-icon icon-class="back" class="icon" />
      </span>
      <span>设置头像</span>
      <span class="link" @click="save">保存</span>
    </div>
    <div class="avatar">
      <img :src="avatar" />
      <p>{{ username }}</p>
    </div>
    <p class="pmt">点击下列图片，选择头像</p>
    <div class="avatar-list">
      <div
        class="avatar-item"
        v-for="img in list"
        :key="img.id"
        @click="change(img.imgUrl)"
      >
        <img :src="img.imgUrl" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "小可爱",
      avatar: require("../../../assets/images/avatar.png"),
      list: [
        { id: 1, imgUrl: require("../../../assets/avatar/a1.png") },
        { id: 2, imgUrl: require("../../../assets/avatar/a2.png") }
      ]
    };
  },
  methods: {
    change(url) {
      this.avatar = url;
    },
    save() {
      this.$toast.success("保存成功！");
      this.close();
    },
    close() {
      this.$emit("close", this.avatar);
    }
  }
};
</script>

<style lang="scss" scoped>
.page {
  padding-bottom: 0;
}
.avatar {
  background-color: #fff;
  text-align: center;
  padding: 15px 0 10px;
  font-size: 120%;
  font-weight: 600;
  img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 0 0 4px #ccc;
    margin: 0 auto 10px;
  }
}
.pmt {
  color: #fff;
  background-color: #666;
  padding: 5px 20px;
}
.avatar-list {
  display: flex;
  flex-wrap: wrap;
  .avatar-item {
    width: 15%;
    margin: 5%;
    img {
      width: 100%;
      border-radius: 50%;
      box-shadow: 0 0 4px #d7d7d7;
    }
  }
}
</style>
